import APIClient from "../../network/index"

const homeSwiper = {
    state: {
        swiperImg:[], //轮播图照片
        bargainirg:[],  //全面推荐数据
        subjectList:[],  //精选专题里数据
        getShopDetails:{}, //商品详情数据
        SubjectDetails:{}, //精选专题里的详情数据
    },
    mutations: {
        //获取轮播图照片
        getSwiperImg(state,goods){
            state.swiperImg = [...goods]
        },
        // 添加全民推荐数据
        getBargainirg(state,goods){
            state.bargainirg = [...goods]
        },
        // 添加专题推荐图片
        getSubjectList(state,goods){
            state.subjectList = [...goods]
        },
        // 添加商品图片详情数据
        getShopDetails(state,goods){
            state.getShopDetails = goods
        },
        // 添加专题详情数据
        getSubjectDetails(state,goods){
            state.SubjectDetails = goods
        }
    },
    actions: {
        getSwiperImg(context){
            APIClient.getHomeSwiperImg().then((res=>{
                console.log*res.data.data
                context.commit("getSwiperImg",res.data.data)
              }))
        },
        getBargainirg(context){
            APIClient.getStoreList().then((res)=>{
                context.commit("getBargainirg",res.data.data)
            })
        },
        getSubjectList(context){
            APIClient.getSubjectList().then((res)=>{
                context.commit("getSubjectList",res.data.data)
            })
        },
        getShopDetails(context,id){
            console.log(id)
            APIClient.get_shop_details({
                params:{id:id}
            }).then((res)=>{
                console.log(res.data)
                context.commit("getShopDetails",res.data.data)
            }).catch((error)=>{
                console.log(error)
            })
        },
        // 获取精选商品 详情数据
        getSubjectDetails(context,id){
            APIClient.getSubjectDetails({
                params:{
                    id:id
                }
            }).then((res)=>{
                context.commit("getSubjectDetails",res.data.data)
            })
        }
    }
}
export default homeSwiper